<{*积分商城-兑换活动详情*}>
<{include file="top_v2.html"}>
</head>
<body>
<div id="wrap" class="pt detail-page">
    <div class="header">
        商品详情
        <a href="javascript:window.history.back();" class="back"></a>
    </div>
    <div class="img-box">
        <img src="<{$preUploadUrl}><{$obj.cover}>" alt="" />
        <p><{$obj.titleInner}></p>
    </div>
    <div class="section">
        <div class="detail">
            <p class="line-1">
                <span>售价:
                <{* 显示积分与价格 *}>
                <{if $obj.point gt 0 and $obj.nowPrice eq 0}>
                    <em><{$obj.point}></em>积分
                <{elseif  $obj.point eq 0 and $obj.nowPrice gt 0 }>
                    <em><{$obj.nowPrice}></em>元
                <{elseif  $obj.point gt 0 and $obj.nowPrice gt 0 }>
                    <em><{$obj.point}></em>积分 +<em><{$obj.nowPrice}></em>元
                <{/if}>
                </span>
                <span class="sale">已售: <em><{$obj.buyNum}></em>件</span>
            </p>
            <p class="line-2">
                <span class="price">￥<{$obj.originalPrice}></span>
                <span class="xg">
                <{if $obj.quota <= 0}> 无限购 <{else}>限<em><{$obj.quota}></em>件<{/if}>

                </span>
            </p>
        </div>
        <div style="display: flex;flex-flow: column">
        <{if $obj.showStock == $POINTMALL_NO_STACK}>
            <div class="buy">已售完</div>
        <{else if $obj.overdue == true}>
            <div class="buy">活动已结束</div>
        <{else}>
            <{if $obj.rest_time gt 0}>  <span class="wait"></span>  <{/if}>
            <a data-time="<{$obj.rest_time}>" data-type = "<{$obj.deliveryType}>" class="buy" id="exchange-btn"><{if $obj.point eq 0 and $obj.nowPrice gt 0}>购 买<{else}>兑 换<{/if}></a>
        <{/if}>
        <{if $obj.isShowStock and $obj.stock gt 0}><div style="font-size: 0.3rem;text-align: center">剩余：<{$obj.showStock}>件</div><{/if}>
        </div>
    </div>
    <div class="title">使用说明</div>
    <div class="intro">
        <{$obj.content}>
    </div>
</div>


<!--关注弹窗-->
<div id="mustFollow" class="pop pop-attention">
    <div class="pop-container">
        <a href="javascript:void(0);" class="pop-close close"></a>
        <div class="pop-header">长按二维码扫描关注</div>
        <div class="pop-content">
            <img src="<{$preStaticUrl}>Wap/images/<{$qrcode_path}>" alt="" class="qrcode"/>
            <p>加客服小妹微信，提交订单，享受优惠福利</p>
            <div class="btn-group" style="display: none;">
                <a href="javascript:void(0);" class="close">知道了</a>
            </div>
        </div>
    </div>
</div>


<div class="pop pop-success" >
    <div class="pop-container">
        <a href="javascript:void(0);" class="pop-close close"></a>
        <div class="pop-content">
            <span class="icon-success"></span>
            <p>兑换成功</p>
            <div class="btn-group">
                <a href="<{U('Card/cardList')}>" class="close">查看我的卡包</a>
            </div>
        </div>
    </div>
</div>


<script>
    var showPop = function(el){
        var pop = $(el).find(".pop-container");
        $(el).show();
        var h = $(pop).height()
        $(pop).css({
            'margin-top': -h/2
        })
    }

    var id="<{$obj.id}>";
    var offs=$('#fixed').offset();
    $(document).ready(function($){
        //倒计时函数
        timeout();
        function timeout(){
            var $point_timeer = $('#exchange-btn');
            var shower = $('.wait');
            var time = parseInt($point_timeer.data("time"));
             $point_timeer.data("time",--time);
             if(time>0){
                 setTimeout(function (){timeout();},1000);
                 $point_timeer.hide();
                 shower.show();
                 output_time(time,shower);
             }else{
                 //秒杀绑定的ajax事件
                 shower.hide();
                 $point_timeer.show().click(clickExchange); //移除disabled属性
             }
        }
        function output_time (time,obj) {
             var hour = Math.floor(time/60/60);
             var minute = Math.floor((time/60)%60);
             var scond = Math.floor(time%60);
             if(hour<10){
                 hour = '0' + hour;
             }
             if(minute<10){
                 minute = '0' + minute;
             }
             if(scond<10){
                 scond = '0' + scond;
             }
             $(obj).html("距开抢"+hour+":"+minute+":"+scond);
        }
    });

    function clickExchange(){
        showPop('#mustFollow');
        $.post("<{u('order')}>",{'id':'<{$obj.id}>'},function(res){console.log(res)});

        //confirmOk();
    }

    doing=false;
    function confirmOk(){
        $('#exchangeConfirm').hide();
        const DELIVERY_SEND = '<{$DELIVERY_SEND}>';
        const DELIVERY_CARD = '<{$DELIVERY_CARD}>';
        const DELIVERY_PHONE = '<{$DELIVERY_PHONE}>';



        var type        = $('#exchange-btn').data('type');
        var restTime    = $('#exchange-btn').data('time');
        if(restTime > 0)
        {
            tip('活动还没开始');
        }else{
                $.ajax({
                    url:"<{U('PointMall/validateExchange')}>",
                    dataType:"json",
                    data:{"id":id},
                    type:"GET",
                    success:function(data){
                        console.log(data);
                        if(data.status == 0){
                            window.location.href = "<{U('PointMall/exchange_deliverWay?id='|cat:$obj.id)}>";
                        }
                        else{
                            if(data.status==99){
                                layer.open({
                                    content: '您的积分不足，查看如何获取积分？'
                                    ,btn: ['确定', '取消']
                                    ,yes: function(index){
                                        location.href="<{U('Point/rule')}>";
                                        layer.close(index);
                                    }
                                });
                            }
                            else if(data.status==2){
                                showPop('#mustFollow');
                            }else{
                                tip(data.msg);
                            }
                        }
                    },

                });
            }
        }
</script>

</body>
</html>




